package com.ies.ieschool.client.module.academic.view.dialog;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.DateItem;
import com.smartgwt.client.widgets.grid.events.RecordDoubleClickEvent;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.form.fields.CanvasItem;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.datepicker.client.DateBox;
import com.google.gwt.user.datepicker.client.DatePicker;
import com.ies.ieschool.client.module.academic.view.content.DropDownSessionView;
import com.ies.ieschool.client.module.academic.view.data.ClassData;
import com.ies.ieschool.client.module.academic.view.data.StudentData;
import com.ies.ieschool.client.module.academic.view.data.SubjectSessionData;
import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.form.fields.DateTimeItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;

public class StudentList {
	private Window winStudentlist;
	ListGrid StudentlistGrid;
	

	public StudentList(RecordDoubleClickEvent event) {

		winStudentlist = new Window();
		winStudentlist.setWidth(1200);
		winStudentlist.setHeight(650);
		winStudentlist.setTitle("รายชื่อนักเรียน");
		winStudentlist.setShowMinimizeButton(false);
		winStudentlist.setIsModal(true);
		winStudentlist.setShowModalMask(true);
		
		HLayout hLayout = new HLayout();
		hLayout.setHeight("34px");
		
		DynamicForm dynamicForm = new DynamicForm();
		dynamicForm.setSize("650px", "29px");
		dynamicForm.setNumCols(4);
		dynamicForm.setFields(new FormItem[] { new DateTimeItem("newDateTimeItem_1", "จากวันที่"), new DateTimeItem("newDateTimeItem_2", "ถึงวันที่")});
		hLayout.addMember(dynamicForm);
		
		IButton btnNewIbutton = new IButton("ตกลง");
		btnNewIbutton.setHeight("28px");
		hLayout.addMember(btnNewIbutton);
		winStudentlist.addItem(hLayout);
		
		StudentlistGrid = new ListGrid(){
			@Override
            protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) {  
  
                String fieldName = this.getFieldName(colNum);  
  
                  if (fieldName.equals("chooseClass")) {  
                	  DropDownSessionView dropdown = new DropDownSessionView();
                	  return dropdown;
                	   
                } else {  
                    return null;  
                }  
  
            }  
        };
        StudentlistGrid.setShowRecordComponents(true);          
        StudentlistGrid.setShowRecordComponentsByCell(true);  
        //StudentlistGrid.setCanRemoveRecords(true);
		StudentlistGrid.setAutoFetchData(true);
		StudentlistGrid.setWidth("1188");
		StudentlistGrid.setDataSource(StudentData.getInstance());
		
		
    	ListGridField lsgfStudentID = new ListGridField("studentID","รหัสนักเรียน");
    	lsgfStudentID.setCellAlign(Alignment.LEFT);
    	lsgfStudentID.setAlign(Alignment.CENTER);
    	
    	ListGridField lsgfStudentName = new ListGridField("studentName","ชื่อ - นามสกุล");
    	lsgfStudentName.setCellAlign(Alignment.LEFT);
    	lsgfStudentName.setAlign(Alignment.CENTER);
    	
    	ListGridField lsgfChooseClass = new ListGridField("chooseClass","เลือกคาบเรียน");
    	lsgfChooseClass.setCellAlign(Alignment.LEFT);
    	lsgfChooseClass.setAlign(Alignment.CENTER);
    	
    	
    	
    	ListGridField lsgfAmount = new ListGridField("amount","จำนวนครั้ง");
    	lsgfAmount.setCellAlign(Alignment.CENTER);
    	lsgfAmount.setAlign(Alignment.CENTER);
    	
    	StudentlistGrid.setFields(lsgfStudentID,lsgfStudentName,lsgfChooseClass,lsgfAmount);
		
		winStudentlist.addItem(StudentlistGrid);
		winStudentlist.centerInPage();
		winStudentlist.show();

		
		
		

		//winStudentlist.addItem(date);

	}

}
